package tokenizers

//CharStream
/**
 * 一个字符串流。其操作为：
 * peek():预读下一个字符，但不移动指针；
 * next():读取下一个字符，并且移动指针；
 * eof():判断是否已经到了结尾。
 */
type CharStream struct {
	data    []byte
	pointer int
	line    int
	col     int
}

func (that *CharStream) Peek() byte {
	if !that.Eof() {
		return that.data[that.pointer]
	}
	return 00

}
func (that *CharStream) Next() byte {
	ch := that.data[that.pointer]
	that.pointer++
	if ch == '\n' {
		that.line++
		that.col = 0
	} else {
		that.col++
	}
	return ch
}
func (that *CharStream) Eof() bool {
	if that.pointer >= len(that.data) {
		return true
	}
	return false
}

func (that *CharStream) IsNil(b byte) bool {
	return b == 00
}

func NewCharStream(data string) *CharStream {
	return &CharStream{
		data:    []byte(data),
		pointer: 0,
		line:    1,
		col:     0,
	}
}
